package com.mapforge.map.tools.undo.tilesetedit;

import com.mapforge.Constants;
import com.mapforge.map.Tileset;

/**
 * An edit representing a change in a tileset's name. This edit is fully
 * undoable and redoable.
 * 
 * @author William Morrison
 * 
 */
public class TilesetNameEdit extends AbstractTilesetEdit {

	/**
	 * The previous name of this tileset.
	 */
	private String name;

	/**
	 * Constructs a new edit. The tileset should already have been renamed.
	 * 
	 * @param tileset
	 *            tileset which was renamed
	 * @param oldName
	 *            old name of tileset
	 */
	public TilesetNameEdit(Tileset tileset, String oldName) {
		super(tileset, Constants.RENAME_EDIT, "Tileset rename");
		this.name = oldName;
	}

	/**
	 * Sets the tileset this edit points to, and its information about the
	 * previous name to null.
	 */
	public void die() {
		tileset = null;
		name = null;
	}

	/**
	 * Saves the tileset's current name and replaces it with its previous name.
	 */
	public void redo() {
		String temp = tileset.getName();
		tileset.setName(name);
		name = temp;
	}

	/**
	 * Saves the tileset's current name and replaces it with its previous name.
	 */
	public void undo() {
		String temp = tileset.getName();
		tileset.setName(name);
		name = temp;
	}
}